// index.js
// 获取应用实例
const app = getApp()

Page({
  data: {
    picPath: app.globalData.picPath,
    scheduleList: [],
    images: [],
    num: '',
    noticeList: [],
    list: [],
    indicatorDots: true,
    vertical: false,
    autoplay: false,
    interval: 2000,
    duration: 500,
    indicatorColor: "#CFCCD0",
    indicatorActiveColor: '#2A6DDD'
  },
  getData() {

    wx.showLoading({
      title: '',
    })
    var url = app.globalData.url + "main/listMain",
      that = this,
      scheduleList = [],
      noticeList = [],
      images = [],
      num = '';

    app.wxRequest(url, {
      memberId: app.globalData.memberId,
      flag: 0,
    }, res => {
      console.log(res);
      if (res.flag) {
        scheduleList = res.data.scheduleList;
        noticeList = res.data.noticeList;
        for (var i in noticeList) {
          if (noticeList[i].member_id == undefined) {
            noticeList[i].flag = false;
          } else {
            noticeList[i].flag = true;
          }
        }
        images = res.data.loopList;
        num = res.data.examNum;
        that.setData({
          scheduleList,
          noticeList,
          images,
          num
        })
        wx.hideLoading()
        wx.stopPullDownRefresh()
      }
    })
  },

  toPage(e) {
    console.log(e);
    var flag = e.currentTarget.dataset.flag;
    if (flag == 'myApproval') {
      wx.navigateTo({
        url: '/managers/pages/my_approval/my_approval',
      })
    } else if (flag == 'approvalAll') {
      wx.navigateTo({
        url: '/managers/pages/approvalAll/approvalAll',
      })
    } else if (flag == 'message') {
      wx.navigateTo({
        url: '/work/pages/message/message',
      })
    } else if (flag == 'schedule') {
      wx.navigateTo({
        url: '/work/pages/riCheng/riCheng',
      })
    }
  },
  toMsgDetail(e) {
    console.log(e);
    var notice_id = e.currentTarget.dataset.flag.notice_id,
      flag = e.currentTarget.dataset.flag.flag;
    wx.setStorageSync('noticeId', notice_id)
    wx.setStorageSync('notice_flag', flag)
    wx.navigateTo({
      url: '/work/pages/message_detail/message_detail',
    })
  },
  toSchedDetail(e) {
    var obj = JSON.stringify(e.currentTarget.dataset.obj);
    wx.navigateTo({
      url: '/work/pages/detail_riCheng/detail_riCheng?obj=' + obj,
    })
  },
  onShow() {
    this.getData()
  },
  onPullDownRefresh() {
    this.getData()
  },
})